home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / GLUT-3.7 / PROGS / GLE / HELIX4.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-12  |  1.6 KB  |  67 lines

  1.  
  2. /* 
  3.  * helicoid (gernalized torus) demo 
  4.  *
  5.  * FUNCTION:
  6.  * This code provides a very simple example of the helicoid primitive.
  7.  * Most of this code is required to set up OpenGL and GLUT, and very
  8.  * very little to set up the helix drawer. Don't blink!
  9.  *
  10.  * =======> MOUSE HOOKED UP TO AFFINE < ========
  11.  *
  12.  * HISTORY:
  13.  * Written by Linas Vepstas, March 1995
  14.  */
  15.  
  16. /* required include files */
  17. #include <GL/glut.h>
  18. #include <GL/tube.h>
  19.  
  20. /*  most recent mouse postion */
  21. extern float lastx;
  22. extern float lasty;
  23.  
  24. void InitStuff (void) {
  25.    lastx = 121.0;
  26.    lasty = 121.0;
  27. }
  28.  
  29. /* draw the helix shape */
  30. void DrawStuff (void) {
  31.    double affine[2][3];
  32.    double delta_affine[2][3];
  33.  
  34.    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  35.    glColor3f (0.7, 0.5, 0.3);
  36.  
  37.    /* set up some matrices so that the object spins with the mouse */
  38.    glPushMatrix ();
  39.    glTranslatef (0.0, 0.0, -80.0);
  40.    glRotatef (220.0, 0.0, 1.0, 0.0);
  41.    glRotatef (65.0, 1.0, 0.0, 0.0);
  42.  
  43.    /* Phew. FINALLY, Draw the helix  -- */
  44.    affine [0][0] = 1.0/ (0.01*lastx);
  45.    affine [1][0] = 0.0;
  46.    affine [0][1] = 0.0;
  47.    affine [1][1] = 0.01*lastx;
  48.    affine [0][2] = 0.0;
  49.    affine [1][2] = 0.0;
  50.  
  51.    delta_affine [0][0] = 0.0;
  52.    delta_affine [1][0] = 0.03*lasty;
  53.    delta_affine [0][1] = -0.03*lasty;
  54.    delta_affine [1][1] = 0.0;
  55.    delta_affine [0][2] = 0.0;
  56.    delta_affine [1][2] = 0.0;
  57.  
  58.    gleSetJoinStyle (TUBE_NORM_EDGE | TUBE_JN_ANGLE | TUBE_JN_CAP);
  59.    gleHelicoid (1.0, 7.0, -1.0, 
  60.                -4.0, 6.0, affine, delta_affine, 0.0, 980.0);
  61.  
  62.    glPopMatrix ();
  63.  
  64.    glutSwapBuffers ();
  65. }
  66. /* ------------------------- end of file ----------------- */
  67.